<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Site extends Controller_App
{
	
	public $site;
	
	/* BEFORE AND AFTER METHODS */
	
	public function before() 
	{
		parent::before();
		
		if(!$this->appconfig['site']['enabled']) {
			$this->request->redirect("app/working");
		}
		
		$this->site = $this->template->content = new View("site/default");
		$this->site->header = new View("site/header");
		$this->site->footer = new View("site/footer");
		$this->site->content = "";
		
		$this->siteMenu();
		
	}
	
	public function after() 
	{
		$scripts = array(
			URL::base() . 'media/lib/jqueryui/js/jquery-1.5.1.min.js',
			URL::base() . 'media/lib/jqueryui/js/jquery-ui-1.8.11.custom.min.js',
		);
		$styles = array(
			URL::base() . 'media/site/css/default.css' => 'screen',
			URL::base() . 'media/site/css/content.css' => 'screen',
			URL::base() . 'media/lib/jqueryui/css/redmond/jquery-ui-1.8.11.custom.css' => 'screen',
		);
		
		$this->template->scripts = array_merge($this->template->scripts, $scripts);
		$this->template->styles = array_merge($this->template->styles, $styles);
		
		parent::after();
	}
	
	public function siteMenu() {
		$this->site->header->menu = array(
			URL::site("site/index") => "Home",
			URL::site("site/books") => "Últimos Libros",
			URL::site("site/notes") => "Notas de Viajeros",
		);
		if(Auth::instance()->logged_in('admin')) {
			$this->site->header->admin_menu = array(
				URL::site("admin/users") => "Usuarios",
				URL::site("admin/books") => "Libros",
				URL::site("admin/authors") => "Autores",
			);
		}
	}
	
	private function adsColumn(){
		$ret = new View("site/index/ads");
		$ads = Model::factory('adv')->find_all();
		$ret->ads = $ads;
		return $ret;
	}
	
	/* ACTIONS: */
	
	public function action_index()
	{
		$this->template->title = "Home";

		$this->site->content = new View("site/content");
		$this->site->content->info = new View("site/index/info");
		$this->site->content->ads = $this->adsColumn();
		
	}
	
	public function action_books() {
		$this->template->title = "Libros";
	}
	
	public function action_notes() {
		$this->template->title = "Notas de Viajeros";
	}		
	
}